import re


# 解析vlm
# 输入： ($SC.SCTESTCD=\"EMPJOB\")
# 输出： [['SC.SCTESTCD', '=', 'EMPJOB']]
def parse_vlm(vlm):
    result = []
    if vlm is None or len(vlm) < 1:
        return result

    vlm = vlm[1:-1]  # 去除括号 $SC.SCTESTCD=\"EMPJOB\"
    splits = vlm.split("&")
    for split in splits:
        details = []
        if len(splits) > 1:
            split = split[1:-1]

        # 处理 '>=' 和 '<=' 的情况
        if ">=" in split or "<=" in split:
            temp = split.split(">=") if ">=" in split else split.split("<=")
            if len(temp[0]) > 1 and temp[0][0] == '$':
                details.append(temp[0][1:])
            else:
                details.append(temp[0])

            details.append(">=" if ">=" in split else "<=")

            if len(temp[1]) > 1 and temp[1][0] == '$':
                details.append(temp[1][1:])
            else:
                details.append(temp[1])
            result.append(details)
            continue

        # 处理其他比较运算符
        temp = re.split(r'[> < = @ #]', split, maxsplit=1)
        if len(temp) == 2:   # ['$SC.SCTESTCD', '"EMPJOB"']
            if len(temp[0]) > 1 and temp[0][0] == '$':
                details.append(temp[0][1:])
            else:
                details.append(temp[0])

            # 正则分割不会保留分隔符，需要从原字符串中提取
            op_index = len(temp[0])
            details.append(split[op_index])  # 添加操作符'='

            if len(temp[1]) > 1 and temp[1][0] == '$':
                details.append(temp[1][1:])
            else:
                if temp[1][0] == '"':
                    details.append(temp[1][1:-1])
                else:
                    details.append(temp[1])
            result.append(details)

    return result


if __name__ == '__main__':
    print(parse_vlm("($SC.SCTESTCD=\"EMPJOB\")"))